﻿using AutoMapper;
using B.S.BasicData.Api.Write.Applications.Command;
using B.S.BasicData.Domains;
using B.S.BasicData.ErrorCode;
using B.S.BasicData.Infrastructures;
using MediatR;

namespace B.S.BasicData.Api.Write.Applications.CommandHandler
{
    public class AddPermissonCommandHandler : IRequestHandler<AddPermissonCommand, ApiResult<int>>
    {
        private readonly IBaseRepository<Permissons> permissonRepository;
        private readonly IMapper mapper;


        public AddPermissonCommandHandler(IBaseRepository<Permissons> permissonRepository, IMapper mapper)
        {
            this.permissonRepository = permissonRepository;
            this.mapper = mapper;
        }

        public async Task<ApiResult<int>> Handle(AddPermissonCommand request, CancellationToken cancellationToken)
        {
            ApiResult<int> result=new ApiResult<int>();
            result.Code=ApiEnum.Success;
            result.Message = "权限添加成功";
            Permissons permissons = new Permissons();
            permissons.PermissonName = request.PermissonName;
            permissons.PermissonValue=request.PermissonValue;
            permissons.PerseId=request.PerseId;
            permissons.IsDel = false;
            result.data=  await permissonRepository.Add(permissons);
            return await Task.FromResult(result);   
        }
    }
}
